package com.liruan.rest.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.liruan.rest.annotation.AuthRequired;
import com.liruan.rest.dto.AuthDTO;
import com.liruan.rest.service.UserService;
import com.msxf.ai.rest.dto.ErrorCodeOnlyDTO;
import com.msxf.ai.rest.response.JSONResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "用户管理")
@RestController
@CrossOrigin
@RequestMapping("user")
public class UserController
{
	@Autowired
	private UserService userService;

	@ApiOperation(value = "用户登录", httpMethod = "POST", consumes = "application/json")
	@GetMapping("login")
	public JSONResponse<AuthDTO> login(@RequestParam String account, @RequestParam String password)
	{
		AuthDTO dto = userService.login(account, password);
		return new JSONResponse<>(dto.errorCode(), dto);
	}
	
	@AuthRequired
	@ApiOperation(value = "用户登出", httpMethod = "POST", consumes = "application/json")
	@GetMapping("logout")
	public JSONResponse<ErrorCodeOnlyDTO> logout()
	{
		ErrorCodeOnlyDTO dto = userService.logout();
		return new JSONResponse<>(dto.errorCode(), dto);
	}
	
}
